package com.ruoyi.tranShort.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tranShort.domain.ShortPerson;
import com.ruoyi.tranShort.service.IShortPersonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员Controller
 * 
 * @author ruoyi
 * @date 2021-08-09
 */
@Api("人员管理")
@RestController
@RequestMapping("/tranShort/person")
public class ShortPersonController extends BaseController
{
    @Autowired
    private IShortPersonService shortPersonService;

    /**
     * 查询人员列表
     */
    @PreAuthorize("@ss.hasPermi('tranShort:person:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShortPerson shortPerson)
    {
        startPage();
        List<ShortPerson> list = shortPersonService.selectShortPersonList(shortPerson);
        return getDataTable(list);
    }

    /**
     * 导出人员列表
     */
    @PreAuthorize("@ss.hasPermi('tranShort:person:export')")
    @Log(title = "人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShortPerson shortPerson)
    {
        List<ShortPerson> list = shortPersonService.selectShortPersonList(shortPerson);
        ExcelUtil<ShortPerson> util = new ExcelUtil<ShortPerson>(ShortPerson.class);
        return util.exportExcel(list, "人员数据");
    }

    /**
     * 获取人员详细信息
     */
    @ApiOperation("/获取人员详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shortPersonService.selectShortPersonById(id));
    }

    /**
     * 新增人员
     */
    @PreAuthorize("@ss.hasPermi('tranShort:person:add')")
    @Log(title = "人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShortPerson shortPerson)
    {
        return toAjax(shortPersonService.insertShortPerson(shortPerson));
    }

    /**
     * 修改人员
     */
    @PreAuthorize("@ss.hasPermi('tranShort:person:edit')")
    @Log(title = "人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShortPerson shortPerson)
    {
        return toAjax(shortPersonService.updateShortPerson(shortPerson));
    }

    /**
     * 删除人员
     */
    @PreAuthorize("@ss.hasPermi('tranShort:person:remove')")
    @Log(title = "人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shortPersonService.deleteShortPersonByIds(ids));
    }

    /**
     * 根据班级获取人员
     * @return
     */
    @ApiOperation("根据班级分组获取人员")
    @GetMapping("/getPersonGroupClassGrade")
    public AjaxResult getPersonGroupClassGrade(){
        return AjaxResult.success(shortPersonService.getPersonGroupClassGrade());
    }
}
